#include <my_head.h>
pthread_cond_t cond;//定义条件变量
pthread_mutex_t lock;
int count = 0;

void *task_func_1(void *arg){
    while(1){
        sleep(10);
        printf("我是生产者线程 [%ld] 生产了一个发动机\n",pthread_self());
        pthread_mutex_lock(&lock);
        pthread_cond_signal(&cond);
        pthread_mutex_unlock(&lock);
    }
}

void *task_func_2(void *arg){
    while(1){
        pthread_mutex_lock(&lock);
        printf("我是消费者线程 [%ld] 完成了前置的组装任务 正在等待发动机产生\n",pthread_self());
        pthread_cond_wait(&cond,&lock);
        printf("我是消费者线程 [%ld] 获取了发动机 完成了组装任务\n",pthread_self());
        pthread_mutex_unlock(&lock);
    }
}

int main(int argc, const char *argv[]){
    pthread_cond_init(&cond,NULL);
    pthread_mutex_init(&cond,NULL)；
    pthread_t tid1,tid2;
    int ret = 0;
    if(0 != (ret = pthread_create(&tid1,NULL,task_func_1,NULL))){
        printf("pthread_create error :[%d] [%s]\n",ret,strerror(ret));
        exit(EXIT_FAILURE);
    }
    if(0 != (ret = pthread_create(&tid2,NULL,task_func_2,NULL))){
        printf("pthread_create error :[%d] [%s]\n",ret,strerror(ret));
        exit(EXIT_FAILURE);
    }
    pthread_join(tid1,NULL);
    pthread_join(tid2,NULL);
    pthread_cond_destroy(&cond);
    pthread_mutex_destroy(&clock);
    return 0;
}